
import config from '@/config'


export default {
  setItem(key, val) {
    const storage = this.getStorage();
    storage[key] = val;
    localStorage[config.namespace] = JSON.stringify(storage);
  },
  getStorage() {
    const storage = localStorage[config.namespace] || '{}';
    return JSON.parse(storage);
  },
  getItem(key) {
    return this.getStorage()[key]
  },
  clearItem() {
    const storage = this.getStorage();
    delete storage[key];
    localStorage[config.namespace] = JSON.stringify(storage);
  },
  clearAll() {
    localStorage.removeItem(config.namespace)
  },
}